// pages/companycurse/companyinfo/companyinfo.js
const App = getApp()
// let AJAX = require('../../../utils/util.js').AJAX
// let timeTranfer = require('../../../utils/util.js').timeTranfer
// let formatRichText = require('../../../utils/util.js').formatRichText
let { AJAX, timeTranfer, formatRichText, imgUrl } = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navH:'',
    curseId:'',
    dataInfo:{},
    imgUrl: imgUrl
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      navH: App.globalData.navHeight,
      curseId:options.id
    })
     if (!wx.getStorageSync("ACCESSTOKEN")) {
        App.userInfoReadyCallback = res => {
           wx.setStorageSync('ACCESSTOKEN', res);
           this.requestInfo()
        }
        return
     }
    this.requestInfo()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  navBack(){
    wx.navigateBack()
  },
  requestInfo(){
    let vm =this
    AJAX("articles/"+vm.data.curseId).then(res=>{
      //console.log(res.data)
      let _data = res.data
      _data.published_at = timeTranfer(_data.published_at,1)
      _data.content = formatRichText(_data.content).replace(/<section/g, '<div').replace(/\/section>/g, '\div>')
      vm.setData({
        dataInfo: _data
      })
    })
  }
})